package com.dt76.smallloanbackenduser.controller.xiaohao;

import com.dt76.smallloanbackenduser.pojo.xiaohao.BorrowOrder;
import com.dt76.smallloanbackenduser.pojo.xiaohao.Contract;
import com.dt76.smallloanbackenduser.pojo.xiaohao.HContractTemplate;
import com.dt76.smallloanbackenduser.remote.xiaohao.BorrowOrderRemote;
import com.dt76.smallloanbackenduser.remote.xiaohao.ContractRemote;
import com.dt76.smallloanbackenduser.remote.xiaohao.ContractTemplateRemote;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class ContractController {

    @Resource
    private ContractTemplateRemote hContractTemplateRemote;
    @Resource
    private BorrowOrderRemote borrowOrderRemote;
    @Resource
    private ContractRemote contractRemote;
    
    @RequestMapping("/Contract/choose")
    @ResponseBody
    public Boolean backToContract(String boID, String contractNo,String mApproveMoney) {
        boolean flag = false;
        HContractTemplate hContractTemplate = hContractTemplateRemote.qryByID(Integer.parseInt(contractNo));
        //消息队列发送合同
        //Todo

        //添加合同信息
        Contract contract = new Contract();
        contract.setCAddress(hContractTemplate.getContractUrl());
        contract.setCContractMoney(Double.parseDouble(mApproveMoney));
        int i1 = contractRemote.addContract(contract);

        //修改订单信息
        BorrowOrder borrowOrder = borrowOrderRemote.qryByID(Integer.parseInt(boID));
        //合同模块做好就把订单状态修改换到合同去
        borrowOrder.setBoType("放款审批");
        System.out.println(i1);
        borrowOrder.setcId(i1);
        int i = borrowOrderRemote.modifyBorrowOrderType(borrowOrder);
        if(i > 0 && i1>0){
            flag =  true;
        }

        return flag;
    }
}
